package com.ruoyi.web.controller.cooperative;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.OrderItem;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.VoOrder;
import com.ruoyi.system.service.IVoOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单Controller
 * 
 * @author ruoyi
 * @date 2022-02-14
 */
@RestController
@RequestMapping("/system/order")
public class VoOrderController extends BaseController
{
    @Autowired
    private IVoOrderService voOrderService;
    /**
     * 查询订单里的商品名字 数量 单价
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/listOrderGoods")
    public TableDataInfo goodsList(VoOrder voOrder)
    {
        String orderId = voOrder.getOrderId();
        List<OrderItem> list = voOrderService.selectGoodsList(orderId);
        return getDataTable(list);
    }

    /**
     * 查询订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(VoOrder voOrder)
    {
        startPage();
        List<VoOrder> list = voOrderService.selectVoOrderList(voOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VoOrder voOrder)
    {
        List<VoOrder> list = voOrderService.selectVoOrderList(voOrder);
        ExcelUtil<VoOrder> util = new ExcelUtil<VoOrder>(VoOrder.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
    {
        return AjaxResult.success(voOrderService.selectVoOrderByOrderId(orderId));
    }

    /**
     * 新增订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VoOrder voOrder)
    {
        return toAjax(voOrderService.insertVoOrder(voOrder));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VoOrder voOrder)
    {
        return toAjax(voOrderService.updateVoOrder(voOrder));
    }

    /**
     * 删除订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds)
    {
        return toAjax(voOrderService.deleteVoOrderByOrderIds(orderIds));
    }
}
